import axios from "axios"
import { API } from '../../config'
import {takeEvery, put } from 'redux-saga/effects'
import { get_products, get_products_success } from "../actions/product";

function* hanleGetProducts(action){
  let response = yield axios.get(`${API}/products`, {
    params: action.payload
  })
  // console.log(res)
  yield put(get_products_success({
    sortBy: action.payload.sortBy,
    products: response.data
    })
  )
}
export default function* productSaga(){
  yield takeEvery(get_products, hanleGetProducts)
}
